// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ResharperComponentSettingsManager.cs" company="Roman '4ux-nbIx' Novitsky">
//   Copyright (c) Roman '4ux-nbIx' Novitsky 2009
// </copyright>
// <summary>
//   Defines the ResharperComponentSettingsManager type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace SettingsManager.ComponentSettingsManagers
{
  #region Namespace Imports

  using System;
  using System.Xml;

  using JetBrains.Annotations;
  using JetBrains.ComponentModel;

  #endregion


  /// <summary>
  /// Describes and manipulates the <c>ReSharper</c> component settings manager.
  /// </summary>
  internal class ResharperComponentSettingsManager : IComponentSettingsManager
  {
    #region Constructors and Destructors

    /// <summary>
    /// Initializes a new instance of the <see cref="ResharperComponentSettingsManager"/> class.
    /// </summary>
    /// <param name="componentTagName">
    /// Name of the component.
    /// </param>
    /// <param name="name">
    /// Name of the settings.
    /// </param>
    public ResharperComponentSettingsManager([NotNull] string componentTagName, [NotNull] string name)
    {
      ComponentTagName = componentTagName;
      Name = name;
    }

    #endregion


    #region Properties

    /// <summary>
    /// Gets the name of the component.
    /// </summary>
    /// <value>
    /// The name of the component.
    /// </value>
    public string ComponentTagName
    {
      get;
      private set;
    }

    /// <summary>
    /// Gets the name of the settings.
    /// </summary>
    /// <value>
    /// The name of the settings.
    /// </value>
    public string Name
    {
      get;
      private set;
    }

    #endregion


    #region Public Methods

    /// <summary>
    /// Gets the options form.
    /// </summary>
    /// <returns>
    /// The options form.
    /// </returns>
    public virtual SettingsManagerOptionsForm GetOptionsForm()
    {
      return null;
    }


    /// <summary>
    /// Loads the options.
    /// </summary>
    /// <param name="optionsElement">
    /// The options element.
    /// </param>
    /// <returns>
    /// Returns an instance of <see cref="System.Object"/>.
    /// </returns>
    /// <exception cref="NotSupportedException">
    /// <c>NotSupportedException</c>.
    /// </exception>
    public virtual object LoadOptions(XmlElement optionsElement)
    {
      throw new NotSupportedException();
    }


    /// <summary>
    /// Loads the settings.
    /// </summary>
    /// <param name="component">The component.</param>
    /// <param name="element">The element.</param>
    /// <param name="options">The options.</param>
    public virtual void LoadSettings([NotNull] IXmlExternalizableComponent component, [NotNull] XmlElement element, [CanBeNull] object options)
    {
      component.ReadFromXml(element);
    }


    /// <summary>
    /// Saves the options.
    /// </summary>
    /// <param name="optionsElement">
    /// The options element.
    /// </param>
    /// <param name="options">
    /// The options.
    /// </param>
    /// <exception cref="NotSupportedException">
    /// <c>NotSupportedException</c>.
    /// </exception>
    public virtual void SaveOptions(XmlElement optionsElement, [NotNull] object options)
    {
      throw new NotSupportedException();
    }


    /// <summary>
    /// Saves the settings.
    /// </summary>
    /// <param name="component">The component.</param>
    /// <param name="element">The element.</param>
    /// <param name="options">The options.</param>
    public virtual void SaveSettings([NotNull] IXmlExternalizableComponent component, [NotNull] XmlElement element, [CanBeNull] object options)
    {
      component.WriteToXml(element);
    }


    /// <summary>
    /// Returns a <see cref="string"/> that represents the current <see cref="object"/>.
    /// </summary>
    /// <returns>
    /// A <see cref="string"/> that represents the current <see cref="object"/>.
    /// </returns>
    /// <filterpriority>2</filterpriority>
    public override string ToString()
    {
      return Name;
    }


    /// <summary>
    /// Updates the settings.
    /// </summary>
    /// <param name="component">The component.</param>
    /// <param name="componentSettingsNode">The component settings node.</param>
    /// <param name="options">The options.</param>
    /// <returns>
    /// Returns <c>true</c>, if there were any changes.
    /// </returns>
    public virtual bool UpdateSettings(
      [NotNull] IXmlExternalizableComponent component, [NotNull] XmlElement componentSettingsNode, [CanBeNull] object options)
    {
      return false;
    }

    #endregion
  }
}